package com.asiainfo.iov.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.framework.customviews.CustomRoundImageView_new;
import com.library.percent.PercentRelativeLayout;
import com.yaxin.yyt.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class Fragment_personal extends Fragment {
    @BindView(R.id.iv_icon)
    CustomRoundImageView_new iv_icon;
    @BindView(R.id.tv_nick)
    TextView tv_nick;
    @BindView(R.id.tv_month)
    TextView tv_month;
    @BindView(R.id.tv_total_earning)
    TextView tv_total_earning;
    @BindView(R.id.tv_sale_count)
    TextView tv_sale_count;
    @BindView(R.id.tv_phone_earning)
    TextView tv_phone_earning;
    @BindView(R.id.iconLayout)
    PercentRelativeLayout iconLayout;
    @BindView(R.id.imageView2)
    ImageView imageView2;
    @BindView(R.id.mysalesLayout)
    LinearLayout mysalesLayout;
    @BindView(R.id.shopInfoLayout)
    LinearLayout shopInfoLayout;
    @BindView(R.id.personalSettingLayout)
    LinearLayout personalSettingLayout;
    Unbinder unbinder;
    private Context mContext;
    private View view;// infalte的布局
    private LinearLayout containerLayout;// 新建容器
    ////////////////////////////////
//    private CustomRoundImageView_new iv_icon;
//    private LinearLayout mysalesLayout, shopInfoLayout, personalSettingLayout;
//    private TextView tv_nick, tv_total_earning, tv_sale_count, tv_phone_earning, tv_month;
    private boolean requestSuccess;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
    }

    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        if (null == view) {
            containerLayout = new LinearLayout(mContext);
            view = inflater.inflate(R.layout.fragment_personal_percent, null);
            view.setMinimumHeight(((WindowManager) getActivity()
                    .getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay().getHeight());
            view.setMinimumWidth(((WindowManager) getActivity()
                    .getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay().getWidth());
            containerLayout.addView(view);
        } else {
            containerLayout.removeAllViews();
            containerLayout = new LinearLayout(getActivity());
            containerLayout.addView(view);
        }
        unbinder = ButterKnife.bind(this, containerLayout);
//        requestHomepageSaleDetail();
        initData();
        return containerLayout;
    }

    private void initData() {
//        if (!TextUtils.isEmpty(imgUrl)) {
//            //glide
//            Glide.with(this).setDefaultRequestOptions(RequestOptions.priorityOf(Priority.HIGH)
//                    .placeholder(R.mipmap.default_icon)
//                    .error(R.mipmap.default_icon).diskCacheStrategy(DiskCacheStrategy.ALL))
//                    .load(imgUrl)
//                    .into(iv_icon);
//        }
//        if (null != tv_nick)
//            tv_nick.setText(TextUtils.isEmpty(nick) ? (TextUtils.isEmpty(phone) ? "店员" : phone) : nick);
    }

    @Override
    public void onResume() {
        super.onResume();
//        if (!requestSuccess) {
//            requestHomepageSaleDetail();
//        }
//        initData();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.iv_icon, R.id.mysalesLayout, R.id.shopInfoLayout, R.id.personalSettingLayout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_icon:
                break;
//            case R.id.mysalesLayout:
//                ((BaseActivity) getContext()).startActivity(MySalesActivity.class);
//                break;
//            case R.id.shopInfoLayout:
//                ((BaseActivity) getContext()).startActivity(ShopInfomationActivity.class);
//                break;
//            case R.id.personalSettingLayout:
//                ((BaseActivity) getContext()).startActivity(PersonalInfomationActivity.class);
////                ((BaseActivity) getContext()).startActivity(PersonalSettingActivity.class);
//                break;
            default:
                break;
        }
    }
}
